export default class DisbursementType {
    static Keys = {
        ID: 'id',
        NAME: 'name',
        ICON : 'icon'
    }

    id: number;
    name: string;
    icon: string;

    static fromJSON = (data: {}): DisbursementType => {
        const type = new DisbursementType();

        type.id = data[DisbursementType.Keys.ID];
        type.name = data[DisbursementType.Keys.NAME];
        type.icon = data[DisbursementType.Keys.ICON];

        return type;
    }
}

export const getIDByName = (types : Array<DisbursementType>, name : string) : number => {
    const [id] =  types.map((type : DisbursementType) => {
        if(type.name == name) {
            return type.id;
        }
    });

    return id;
}

export const getNameByID = (types : Array<DisbursementType>, id : number) : string => {
    const [name] =  types.map((type : DisbursementType) => {
        if(type.id == id) {
            return type.name;
        }
    });

    return name;
}

export const getIconByID = (types : Array<DisbursementType>, id : number) : string => {
    const [icon] =  types.map((type : DisbursementType) => {
        if(type.id == id) {
            return type.icon;
        }
    });

    return icon;
}